package com.travel;

import java.util.Scanner;

public class Main {
    static int gcd(int a,int b){
        return b==0?a:gcd(b,a%b);
    }
    static int phi(int p){
        int res=0;
        for(int i =1;i<p;i++){
            if(gcd(i,p)==1)res++;
        }
        return res;
    }
    static int g(int a,int b){
        if(a==2023){
            if(a<=b){
                return a;
            }else{
                return a%b+b;
            }
        }
        int d=g(a+1,phi(b));
        int res=1;
        for (int i = 1; i <= d; ++i) {
            res = (res * a) % b;
        }
        if (d * Math.log(a) > Math.log(b)) {
            res += b;
        }
        return res;
    }
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        //在此输入您的代码...
        System.out.println(g(2,2023)%2023);
        scan.close();
    }
}